#ifndef __GLES2FBO_H__
#define __GLES2FBO_H__

#include "GLES2RenderTexture.h"
#include "GLES2Context.h"

namespace PVM
{
	class GLES2FBOManager;
	struct GLES2SurfaceDesc;
	
	class GLES2FrameBufferObject
	{
	public:
		GLES2FrameBufferObject(GLES2FBOManager* manager, uint fsaa);
		~GLES2FrameBufferObject();
		
		void bindSurface(size_t attachment, const GLES2SurfaceDesc& target);
		void unbindSurface(size_t attachment);
		
		void bind();
		void swapBuffers();
		
		void attachDepthBuffer(DepthBuffer* depthBuffer);
		void detachDepthBuffer();
		
		size_t getWidth();
		size_t getHeight();
		PixelFormat getFormat();
		GLsizei getFSAA();
		
		GLES2FBOManager* getManager() {return mManager;}
		const GLES2SurfaceDesc& getSurface(size_t attachment) {return mColour[attachment];}
		
	private:
		GLES2FBOManager* mManager;
		GLsizei mNumSamples;
		GLuint mFB;
		GLuint mMultisampleFB;
		GLES2SurfaceDesc mMultisampleColourBuffer;
		GLES2SurfaceDesc mDepth;
		GLES2SurfaceDesc mStencil;
		
		GLES2SurfaceDesc mColour[MAX_MULTIPLE_RENDER_TARGETS];
		
		void initialise();
	};
}

#endif
